package com.hxzy.module.admin.controller;

import com.github.pagehelper.PageInfo;
import com.hxzy.framework.common.exception.ApiException;
import com.hxzy.framework.common.resp.R;
import com.hxzy.framework.common.resp.ResultCode;
import com.hxzy.module.admin.api.account.req.AccountListReq;
import com.hxzy.module.admin.api.account.resp.AccountDetailResp;
import com.hxzy.module.admin.api.account.resp.AdminAccountListResp;
import com.hxzy.module.admin.api.account.resp.LoadUserResp;
import com.hxzy.module.admin.service.AdminAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @Author wy
 * @Description 后台用户管理
 * @Date 2024/1/28 11:20
 * @Version 1.0
 */
@Api(tags = "后台用户-账户管理Api")
@RestController
@RequestMapping("/ums")
public class AdminAccountController {

    /**
     * 管理员账户
     */
    @Autowired
    private AdminAccountService adminAccountService;

    /**
     * 获取当前用户信息 (相关的表 admin_account , admin_account_inner_role , admin_role ,admin_menu,admin_module,admin_role_inner_module)
     * @param accountId
     * @return
     */
    @ApiOperation(value = "获取当前用户信息", notes = "获取当前用户信息")
    @GetMapping(value = "/loadUser/{accountId}")
    public R<LoadUserResp> loadUser(@PathVariable(value = "accountId") Long accountId) {
        return R.success(this.adminAccountService.loadUser(accountId));
    }

    @ApiOperation(value = "帐号列表", notes = "帐号列表")
    @GetMapping(value = "/accountList")
    public R<PageInfo<AdminAccountListResp>> accountList(@Validated AccountListReq req){
        return R.success(this.adminAccountService.accountList(req));
    }


    @ApiOperation(value = "帐号详情", notes = "帐号详情")
    @GetMapping(value = "/accountDetail/{accountId}")
    public R<AccountDetailResp> accountDetail(@PathVariable(value = "accountId") Long accountId) {
        if(Objects.isNull(accountId)){
            throw new ApiException(ResultCode.MISSING_REQUEST_PARAM_ERROR.getCode(),"角色编号不能为空!");
        }
        return R.success(this.adminAccountService.accountDetail(accountId));
    }


}
